class Solution(object):
    def maximumScore(self, nums, multipliers):
        n = len(nums)
        m = len(multipliers)
        DP = [[0 for _ in range(m + 1)] for _ in range(m + 1)]
        for i in range(1, m + 1):
            DP[i][0] = DP[i - 1][0] + nums[i - 1] * multipliers[i - 1]
        for i in range(m + 1):
            for j in range(1, m + 1 - i):
                if i == 0:
                    DP[i][j] = DP[i][j - 1] + nums[n - j] * multipliers[j - 1]
                else:
                    DP[i][j] = max(DP[i - 1][j] + nums[i - 1] * multipliers[i + j - 1],
                                   DP[i][j - 1] + nums[n - j] * multipliers[i + j - 1])
        return max([DP[i][m - i] for i in range(m + 1)])

